<?php

namespace app\common\model\xilujob;

use think\Model;


class Navigation extends Model
{

    

    

    // 表名
    protected $name = 'xilujob_navigation';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'icon_image_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getGroupList()
    {
        return ['1' => __('Group 1'), '2' => __('Group 2')];
    }
    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }

    public function getJumpTypeList()
    {
        return ['1' => __('Jump_type 1'), '2' => __('Jump_type 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function setGroupAttr($value, $data = [])
    {
        return is_array($value) ? implode(',',$value): '';
    }


    public function getIconImageTextAttr($value,$data){
        $value = isset($data['icon_image']) && $data['icon_image'] ? $data['icon_image'] : '';
        return $value?cdnurl($value,true):'';
    }
    /**
     * 获取
     * @param $group
     */
    public static function getNavigation($group) {
        $list = self::field("id,name,icon_image,type,mini_appid,jump_type,url")
            ->where("FIND_IN_SET($group,`group`)")
            ->where('status','1')
            ->order('weigh','asc')
            ->select();
        return $list;
    }


}
